<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>
        <c:choose>
            <c:when test="${flag==1}">激活账户</c:when>
            <c:otherwise>找回密码</c:otherwise>
        </c:choose>
    </title>
    <link rel="shortcut icon" href="/favicon1.ico" type="image/x-icon">
    <meta charset="utf-8">
    <base href="<%=request.getContextPath()%>/">
    <link href="static/plugin/bootstrapValidator/css/bootstrapValidator.css" rel="stylesheet">
    <link href="static/plugin/sweetAlert/css/sweet-alert.css" rel="stylesheet">
    <link href="static/bootstrap/css/bootstrap.css" rel="stylesheet">

    <style>
        .loginBody {
            background: url("<%=request.getContextPath()%>/static/layout/image/login_bg.jpg") no-repeat #E9F0F4;
        }

        .btn-blue {
            height: 40px;
            line-height: 40px;
            padding: 0;
            border: none;
            background-color: #66b7ff;
            color: #fff !important;
            border-radius: 2px;
        }

        .btn-blue:hover {
            background-color: #4DAAFF;
        }

        .aw-register-box input[type="text"], .aw-register-box input[type="password"] {
            width: 100%;
            height: 40px;
            line-height: 28px \0;
            padding-left: 15px !important;
            box-shadow: none;
            border-color: #e6e6e6;
        }

        .input-group-addon {
            padding: 6px 12px;
            font-size: 14px;
            font-weight: normal;
            line-height: 1;
            color: #3c763d;
            text-align: center;
            background-color: #ffffff;
            border: 1px solid #e6e6e6;
            border-radius: 4px;
        }

        .has-success .input-group-addon {
            /*color: #3c763d;*/
            background-color: #ffffff;
            border-color: #e6e6e6;
        }

        .has-success .form-control:focus {
            border-color: #e6e6e6;
            -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .0), 0 0 6px #e6e6e6;
        }

        h3 {
            margin: 45px 0 0;
            font-size: 20px;
            color: #666666;
        }

        h2 {
            font-family: '楷体';
            margin-bottom: 10px;
            font-size: 30px;
            line-height: 1.2;
            font-weight: bold;
            color: #333;
        }

        .waitImg {
            background-image: url("<%=request.getContextPath()%>/static/layout/image/wait.gif");
            height: 30px;
            width: 30px;
            background-repeat: no-repeat;
            background-size: 30px 30px;
            margin: 0 auto;
        }

        #main {
            position: absolute;
            width: 680px;
            height: 600px;
            left: 50%;
            top: 50%;
            margin-left: -340px;
            margin-top: -300px;
            background-color: #ffffff;
            border-radius: 4px
        }


    </style>


</head>

<body class="loginBody">

<div>
    <div id="main">
        <div style="height: 180px ;padding-top: 50px">
            <h2 align="center" class="">上海市质监局专家管理系统</h2>
        </div>

        <form id="form_data" class="form-horizontal row ">

            <div class="form-group col-sm-12 " style="margin-bottom: 20px">
                <div class="col-sm-6  col-sm-offset-3 aw-register-box">
                    <h3 style="display: block;margin: 0px auto;text-align: center">
                        <c:choose>
                            <c:when test="${flag==1}">激活账户</c:when>
                            <c:otherwise>找回密码</c:otherwise>
                        </c:choose>
                    </h3>
                </div>
            </div>

            <div class="form-group col-sm-12 " style="margin-bottom: 20px">
                <div class="col-sm-6  col-sm-offset-3 aw-register-box">
                    <div class="input-group  ">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-user"></span></span>
                        <input type="text" class="form-control  " name="name" placeholder="姓名">
                    </div>
                </div>
            </div>

            <div class="form-group col-sm-12 " style="margin-bottom: 20px">
                <div class="col-sm-6 col-sm-offset-3 aw-register-box">
                    <div class="input-group ">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-credit-card"></span></span>
                        <input type="text" class="form-control " name="idCard" placeholder="身份证号码">
                    </div>

                </div>
            </div>

            <div class="form-group col-sm-12 " style="margin-bottom: 20px">
                <div class="col-sm-6 col-sm-offset-3 aw-register-box">
                    <div class="input-group ">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-phone"></span></span>
                        <input type="text" class="form-control " name="phone" placeholder="手机号码">
                    </div>

                </div>
            </div>


            <div class="form-group col-sm-12 " style="margin-bottom: 20px">
                <div class="col-sm-6 col-sm-offset-3 aw-register-box">
                    <div class="input-group ">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-envelope"></span></span>
                        <input type="text" style="border-radius: 0 4px 4px 0" class="form-control " name="code"
                               placeholder="短信验证码">
                        <div class="input-group-btn">
                            <button style="margin-left: 5px;border-radius: 4px" type="button" id="btnSendCode"
                                    onClick="sendMessage()" class="btn btn-default">获取验证码
                            </button>
                        </div>
                    </div>
                </div>

            </div>
            <input name="flag" type="hidden" value="${flag}">

            <div class="form-group col-sm-12">
                <div class="col-sm-6  col-sm-offset-3">
                    <button id="btn_submit" style="width: 100%;text-align: center" type="submit"
                            class="btn btn-lg btn-blue btn-block">
                        &nbsp;确&nbsp;定&nbsp;</button>
                </div>
            </div>

            <div class="form-group col-sm-12">
                <div id="div_error" style="color: #a13314" class="col-sm-6  col-sm-offset-3 ">
                </div>
            </div>
            <div class="form-group col-sm-12">
                <div class="col-sm-6 col-sm-offset-3 ">
                    服务热线： <br>工业产品生产许可证： 021-64855341；<br>检验检测：021-64857495。
                </div>
            </div>

        </form>
    </div>
</div>

<script src="static/jquery/jquery-1.9.1.min.js"></script>
<script src="static/bootstrap/js/bootstrap.js"></script>
<script src="static/plugin/bootstrapValidator/js/bootstrapValidator.min.js"></script>
<script src="static/plugin/sweetAlert/js/sweet-alert.js"></script>
<script type="text/javascript">
    var InterValObj; //timer变量，控制时间
    var count = 60; //间隔函数，1秒执行
    var curCount;//当前剩余秒数
    function sendMessage() {
        var bv = $("#form_data").data('bootstrapValidator');
        var name = bv.validateField("name").isValidField('name');
        var idCard = bv.validateField("idCard").isValidField('idCard');
        var phone = bv.validateField("phone").isValidField('phone');
        if (name + idCard + phone == 3) {
            curCount = count;
            //设置button效果，开始计时
            $("#btnSendCode").attr("disabled", "true");
            $("#btnSendCode").html("正在发送...");
            $("#div_error").html('');

            $.ajax({
                type: "POST",
                url: 'welcome/signUp/getPhoneCode', //目标地址
                data: $("#form_data").serialize(),
                error: function () {
                    $("#btnSendCode").attr("disabled", false);
                    $("#btnSendCode").html("重新发送验证码");
                    $("#div_error").html("短信发送异常");
                },
                success: function (data) {
                    if (data.status == 1) {
                        $("#btnSendCode").html(curCount + "秒再获取");
                        InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次
                    } else {
                        $("#btnSendCode").attr("disabled", false);
                        $("#btnSendCode").html("重新发送验证码");
                        $("#div_error").html(data.message);
                    }
                }
            });
        }
    }
    //timer处理函数
    function SetRemainTime() {
        if (curCount == 0) {
            window.clearInterval(InterValObj);//停止计时器
            $("#btnSendCode").removeAttr("disabled");//启用按钮
            $("#btnSendCode").html("重新发送验证码");
            code = ""; //清除验证码。如果不清除，过时间后，输入收到的验证码依然有效
        }
        else {
            curCount--;
            $("#btnSendCode").html(curCount + "秒再获取");
        }
    }
</script>


<script>
    $(function () {
        <%--bootstrapValidator--%>
        $("#form_data").bootstrapValidator({

            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                name: {
                    validators: {
                        notEmpty: {
                            message: '不能为空！'
                        }
                    }
                }, idCard: {
                    validators: {
                        regexp: {
                            regexp: /^[0-9]*(X|x)?$/,
                            message: '出现非法字符！'
                        },
                        stringLength: {
                            max: 18,
                            min: 18,
                            message: '不满足18位！'
                        },
                        notEmpty: {
                            message: '不能为空！'
                        }
                    }
                },
                phone: {
                    validators: {
                        digits: {
                            message: '出现非法字符！'
                        }
                        ,
                        stringLength: {
                            max: 11,
                            min: 11,
                            message: '不满足11位！'
                        },
                        notEmpty: {
                            message: '不能为空！'
                        }
                    }
                },
                code: {
                    validators: {
                        digits: {
                            message: '出现非法字符！'
                        }
                        ,
                        stringLength: {
                            max: 6,
                            min: 6,
                            message: '不满足6位！'
                        },
                        notEmpty: {
                            message: '不能为空！'
                        }
                    }
                }
            }
        }).on('success.form.bv', function (e) {
            e.preventDefault();
            $("#btn_submit").html('<div class="waitImg"></div>');
            $("#div_error").html("");


            $.ajax({
                type: "POST",
                url: 'welcome/signUp/validatorInfo',
                data: $(e.target).serialize(),
                error: function () {
                    $("#div_error").html('系统异常');
                    $("#btn_submit").html('&nbsp;确&nbsp;定&nbsp;');
                },
                success: function (data) {
                    if (data.status == '1') {
                        swal({
                                    title: "验证成功",
                                    type: "success",
                                    showConfirmButton: true
                                }, function () {
                                    window.location.href = "welcome/signUp/setPasswordPage";
                                }
                        );


                    } else {
                        $("#form_data").data('bootstrapValidator').resetForm();
                        $("#div_error").html(data.message);
                        $("#btn_submit").html('&nbsp;确&nbsp;定&nbsp;');
                    }
                }
            });

        });
    });
</script>


</body>

</html>